// import Home from '@/pages/Home'
// import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/myOrder'
import groupOrder from '@/pages/Center/groupOrder'
// 把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件
// const foo=()=>{
//   return import("@/pages/Home")
// }
export default [
  {
    path: '/home',
    //路由懒加载简化写法
    component:()=>import("@/pages/Home"),
    meta: { show: true },
  },
  {
    // params传参需要在地址栏添加参数名和添加name
    //如果路由上面不写参数，也是可以传过去的，但不会在url上面显示出你的参数，
    // 并且当你跳到别的页面或者刷新页面的时候参数会丢失（如下图所示），那依赖这个参数的http请求或者其他操作就会失败。
    //params参数可以传递或者不传递。在后面添加一个？
    path: '/search/:keyword?',
    // path: '/search/',

    component: ()=>import("@/pages/Search"),
    // 路由元信息
    meta: { show: true },
    name: 'search',
  },
  {
    path: '/login',
    component: Login,
    meta: { show: false },
  },
  {
    path: '/register',
    component: Register,
    meta: { show: false },
  },
  {
    path: '/detail/:skuId',
    component: Detail,
    meta: { show: true },
  },
  {
    path: '/addcartsuccess',
    component: AddCartSuccess,
    name: 'addcartsuccess',
    meta: { show: true },
  },
  {
    path: '/shopcart',
    component: ShopCart,
    name: 'shopcart',
    meta: { show: true },
  },
  {
    path: '/trade',
    component: Trade,
    name: 'trade',
    meta: { show: true },
    //路由独享守卫
    beforeEnter:(to,from,next)=>{
      if(from.path=='/shopcart'){
        next()
      }else{
        next(false)
      }
    }
  },
  {
    path: '/pay',
    component: Pay,
    name: 'pay',
    meta: { show: true },
    beforeEnter:(to,from,next)=>{
      if(from.path=='/trade'){
        next()
      }else{
        next(false)
      }
    }
  },
  {
    path: '/paysuccess',
    component: PaySuccess,
    name: 'paysuccess',
    meta: { show: true },
  },
  {
    path: '/center',
    redirect:'/center/myorder',
    component: Center,
    meta: { show: true },
    children: [
      {
        
        path: 'myorder',
        component: MyOrder,
      },
      {
        path: 'grouporder',
        component: groupOrder,
      },
    ],
  },
  {
    path: '*',
    redirect: '/home',
  },
]
